﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace MecSom_Wpf {
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class Principal : Window {

        public Principal() {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e) {
            this.servico.Pesquisa = this.pesquisa;
        }

        private void btnPesquisa_Click(object sender, RoutedEventArgs e) {
            this.pesquisa.Visibility = Visibility.Visible;
            this.servico.Visibility = Visibility.Collapsed;
        }

        private void btnServiços_Click(object sender, RoutedEventArgs e) {
            var resposta = MessageBoxResult.Yes;

            if (!this.pesquisa.PossuiFiltro && !this.servico.PossuiRegistros)
                resposta = MessageBox.Show("Nenhum campo foi preenchido na pesquisa, então esse carregamento pode demorar.\n\nDeseja continuar?", "Pesquisa em branco", MessageBoxButton.YesNo, MessageBoxImage.Warning);

            if (resposta == MessageBoxResult.Yes) {
                this.pesquisa.Visibility = Visibility.Collapsed;
                this.servico.Visibility = Visibility.Visible;

                if (!this.servico.PossuiRegistros)
                    this.servico.CarregarClientes();
            }
        }

        private void pesquisa_Pesquisar(object sender, EventArgs e) {
            this.pesquisa.Visibility = Visibility.Collapsed;
            this.servico.Visibility = Visibility.Visible;

            this.servico.CarregarClientes();
        }

    }
}
